package cn.stylefeng.guns.modular.customer.controller;

import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.customer.entity.Customer;

import cn.stylefeng.guns.modular.customer.service.CustomerService;
import cn.stylefeng.roses.core.base.controller.BaseController;
import cn.stylefeng.roses.kernel.model.response.ResponseData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


/**
 * 用户表控制器
 *
 * @author typ
 * @Date 2021-04-25 17:37:00
 */
@Controller
@RequestMapping("/customer")
public class CustomerController extends BaseController {

    private String PREFIX = "/customer/customer";

    @Autowired
    private CustomerService customerService;

    /**
     * 跳转到主页面
     *
     * @author typ
     * @Date 2021-04-25
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "/customer.html";
    }

    /**
     * 新增页面
     *
     * @author typ
     * @Date 2021-04-25
     */
    @RequestMapping("/add")
    public String add() {
        return PREFIX + "/customer_add.html";
    }

    /**
     * 编辑页面
     *
     * @author typ
     * @Date 2021-04-25
     */
    @RequestMapping("/edit")
    public String edit() {
        return PREFIX + "/customer_edit.html";
    }

    /**
     * 新增接口
     *
     * @author typ
     * @Date 2021-04-25
     */
    @RequestMapping("/addItem")
    @ResponseBody
    public ResponseData addItem(Customer customerParam) {
        this.customerService.add(customerParam);
        return ResponseData.success();
    }

    /**
     * 编辑接口
     *
     * @author typ
     * @Date 2021-04-25
     */
    @RequestMapping("/editItem")
    @ResponseBody
    public ResponseData editItem(Customer customerParam) {
        this.customerService.update(customerParam);
        return ResponseData.success();
    }

    /**
     * 删除接口
     *
     * @author typ
     * @Date 2021-04-25
     */
    @RequestMapping("/delete")
    @ResponseBody
    public ResponseData delete(Customer customerParam) {
        this.customerService.delete(customerParam);
        return ResponseData.success();
    }

    /**
     * 查看详情接口
     *
     * @author typ
     * @Date 2021-04-25
     */
    @RequestMapping("/detail")
    @ResponseBody
    public ResponseData detail(Customer customerParam) {
        Customer detail = this.customerService.getById(customerParam.getId());
        return ResponseData.success(detail);
    }

    /**
     * 查询列表
     *
     * @author typ
     * @Date 2021-04-25
     */
    @ResponseBody
    @RequestMapping("/list")
    public LayuiPageInfo list(Customer customerParam) {
        return this.customerService.findPageBySpec(customerParam);
    }

}


